package com.example.web;


import com.example.fanqie.entity.Chapter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class progressDao {

    @Autowired
    StringRedisTemplate redisTemplate;

    @RequestMapping("setprogress")
    public String setprogress(@RequestBody Chapter chapter) {
        if(chapter.getProgress() != 0){
            redisTemplate.opsForValue().set(chapter.getNovelId().toString(), String.valueOf(chapter.getProgress()));
            return "进度已更新";
        }

        return "进度未更新";

    }

    @RequestMapping("getprogress")
    public Integer getprogress(@RequestBody Chapter chapter) {

        String str = redisTemplate.opsForValue().get(chapter.getNovelId().toString());
        return    Integer.valueOf(str);

    }

    @RequestMapping("deleteprogress")
    public String deleteprogress(@RequestBody Chapter chapter) {
        redisTemplate.delete(chapter.getNovelId().toString());
        return "进度已删除";

    }


}
